﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLab.Utility;
using System.Windows.Controls;
using AvalonDock;
using System.Windows.Input;
using Microsoft.Practices.Prism.Commands;
using QLab.Services;

namespace QLab.Controllers
{
	/// <summary>
	/// Klasa koja mora biti nasledjena da bi odgovarajuci podaci mogli da budu prikazani kao tab
	/// </summary>
	public class TabBase : DocumentContent
	{
		private readonly string _tabHeaderPath;		//Koji ce property biti bindovan u title
		private readonly UserControl _view;			//Kontrola koja prikazuje sadrzaj unutar taba

		private IStatusBarService _statusBarService;
		private ICommand _saveCommand;
		private ICommand _cutCommand;
		private ICommand _copyCommand;
		private ICommand _pasteCommand;
		private ICommand _undoCommand;
		private ICommand _redoCommand;

		public TabBase(UserControl view)
		{
			_view = view;
			base.Content = view;

			this.Closing += new EventHandler<System.ComponentModel.CancelEventArgs>(TabBase_Closing);
			this.Closed += new EventHandler(TabBase_Closed);

			_saveCommand = new DelegateCommand(Save, CanSaveExecute);
			_cutCommand = new DelegateCommand(Cut);
			_copyCommand = new DelegateCommand(Copy);
			_pasteCommand = new DelegateCommand(Paste);
			_undoCommand = new DelegateCommand(Undo);
			_redoCommand = new DelegateCommand(Redo);
		}

		public TabBase(UserControl view, string tabHeaderPath)
		{
			_view = view;
			_tabHeaderPath = tabHeaderPath;

			view.DataContext = this;
		}

		#region Properties

		public UserControl View	{ get { return _view; }	}

		public string TabHeaderPath	{ get { return _tabHeaderPath; } }

		public ICommand SaveCommand { get { return _saveCommand; } }

		public ICommand CutCommand { get { return _cutCommand; } }

		public ICommand CopyCommand { get { return _copyCommand; } }

		public ICommand PasteCommand { get { return _pasteCommand; } }

		public ICommand UndoCommand { get { return _undoCommand; } }

		public ICommand RedoCommand { get { return _redoCommand; } }

		public IStatusBarService StatusBarService
		{
			get { return _statusBarService; }
			set 
			{
				_statusBarService = value;
				RaisePropertyChanged("StatusBarService");
			}
		}

		#endregion

		#region Methods

		protected virtual bool CanSaveExecute()
		{
			return true;
		}
		protected virtual void Save()
		{

		}
		protected virtual void Cut()
		{

		}
		protected virtual void Copy()
		{

		}
		protected virtual void Paste()
		{

		}
		protected virtual void Undo()
		{

		}
		protected virtual void Redo()
		{

		}

		internal virtual bool EqualTo(TabBase Other)
		{
			return this == Other;
		}

		#endregion


		#region Event Handlers

		void TabBase_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			
		}

		void TabBase_Closed(object sender, EventArgs e)
		{
			//MainWindowController.Instance().TabController.RemoveTab(this);
		}

		#endregion

		
	}
}

